<?php

namespace App\Models;

use App\Models\Traits\HasScopeInquire;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

/**
 * App\Models\GoldCash
 *
 * @property int $id
 * @property int $user_id
 * @property string|null $origin
 * @property string|null $result
 * @property string|null $cashes
 * @property string|null $remark
 * @property string|null $reason
 * @property string|null $data
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @method static \Database\Factories\GoldCashFactory factory(...$parameters)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldCash newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|GoldCash newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|GoldCash query()
 * @method static \Illuminate\Database\Eloquent\Builder|GoldCash whereCashes($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldCash whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldCash whereData($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldCash whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldCash whereOrigin($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldCash whereReason($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldCash whereRemark($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldCash whereResult($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldCash whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|GoldCash whereUserId($value)
 * @mixin \Eloquent
 * @property string|null $money
 * @method static \Illuminate\Database\Eloquent\Builder|GoldCash whereMoney($value)
 * @property-read \App\Models\User|null $user
 * @method static Builder|GoldCash beanCashes()
 * @method static Builder|GoldCash firstCashes()
 * @method static Builder|GoldCash inquire($condition = null)
 * @method static Builder|GoldCash payRecord()
 * @method static Builder|GoldCash presentCashes()
 * @method static Builder|GoldCash supportCashes()
 */
class GoldCash extends Model
{
    use HasFactory, HasScopeInquire;

    protected $guarded = ['id'];

    protected $casts = [
        'data' => 'json'
    ];

    static array $inquireConditions = [
        'bean_cashes' => '金豆兑换',
        'support_cashes' => '平台扶持',
        'first_cashes' => '直邀赠送',
        'present_cashes' => '平台赠送',
        'pay_record' => '金店订单支出',
    ];

    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class);
    }

    public function scopeBeanCashes(Builder $builder): Builder
    {
        return $builder->where('remark', 'gold_cashes_from_beans');
    }

    public function scopeSupportCashes(Builder $builder): Builder
    {
        return $builder->where('remark', 'support_gold_cashes');
    }

    public function scopeFirstCashes(Builder $builder): Builder
    {
        return $builder->where('remark', 'child_first_gold_record_cashes');
    }

    public function scopePresentCashes(Builder $builder): Builder
    {
        return $builder->where('remark', 'present_gold_cashes');
    }

    public function scopePayRecord(Builder $builder): Builder
    {
        return $builder->where('remark', 'pay_gold_record');
    }
}
